package com.shire.shire_interface.service.marketing;

import com.shire.shire_interface.dao.group.VGroupInviteHistoryDao;
import com.shire.shire_interface.dao.marketing.WxGroupAwardDao;
import com.shire.shire_interface.model.group.VGroupInviteHistoryExample;
import com.shire.shire_interface.model.marketing.WxGroupAward;
import com.shire.shire_interface.model.marketing.WxGroupAwardExample;
import com.shire.shire_interface.model.marketing.WxGroupAwardWithBLOBs;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WxGroupAwardService {
    @Resource
    private WxGroupAwardDao groupAwardDao;

    @Resource
    private VGroupInviteHistoryDao inviteHistoryDao;

    public Integer insetGroupAward(WxGroupAwardWithBLOBs wxGroupAward) {
        return groupAwardDao.insertSelective(wxGroupAward);
    }

    public List<WxGroupAwardWithBLOBs> getGroupAwardHistory(WxGroupAwardExample example) {
        return groupAwardDao.selectByExampleWithBLOBs(example);
    }

    public WxGroupAward selectByPrimaryKey(Integer awardId) {
        return groupAwardDao.selectByPrimaryKey(awardId);
    }

    public Long getInverteeCount(String wxAccount, String inviterWxid){
        VGroupInviteHistoryExample example = new VGroupInviteHistoryExample();
        example.createCriteria().andWxAccountEqualTo(wxAccount).andInviterWxidEqualTo(inviterWxid);

        return  inviteHistoryDao.countInviterByExample(example);
    }

    public Integer updateByPrimaryKey(WxGroupAwardWithBLOBs wxGroupAward) {
        return groupAwardDao.updateByPrimaryKeySelective(wxGroupAward);
    }

    public Integer deleteByPrimaryKey(Integer awardId) {
        return groupAwardDao.deleteByPrimaryKey(awardId);
    }
}
